package top.zhongyy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import top.zhongyy.pojo.Blog;
import top.zhongyy.service.BlogService;

/**
 * @Created by IntelliJ IDEA.
 * @DESC:博客详情处理界面
 * @Author: Andy
 * @Date: 2021/4/1
 */

@Controller
@RequestMapping("/blog")
public class BlogDealController {
    
    @Autowired
    BlogService blogService;
    
    @GetMapping("/{blogId}/praise")
    public String praise(@PathVariable("blogId") Long blogId, Model model) {
        Blog blog = blogService.getById(blogId);
        blog.setPraise(blog.getPraise() + 1);
        blogService.updateById(blog);
        model.addAttribute("blog", blogService.getById(blogId));
        return "blog :: praiseCount";
        
    }
    
    @GetMapping("/{blogId}/yuck")
    public String yuck(@PathVariable("blogId") Long blogId, Model model) {
        Blog blog = blogService.getById(blogId);
        blog.setYuck(blog.getYuck() + 1);
        blogService.updateById(blog);
        model.addAttribute("blog", blogService.getById(blogId));
        return "blog :: yuckCount";
    }
}
